package ljye.com.ljye.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.github.mikephil.charting.charts.RadarChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.RadarData;
import com.github.mikephil.charting.data.RadarDataSet;

import java.util.ArrayList;

import ljye.com.ljye.R;
import ljye.com.ljye.utils.Utils;

public class Activity_Rating_Interpretation extends FragmentActivity {


    public View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.back://返回
                    finish();
                    break;

                default:
                    break;
            }
        }
    };
    private ImageView back;//返回
    private RadarChart mChart;
    private TextView number;//数字
    private String[] mParties = new String[] {
            " ", " ", " ", " ",  ""
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rating_interpretation);
        Utils.setColor(Activity_Rating_Interpretation.this, Color.parseColor("#FF8D59"));//橙色状态栏
        initView();
        initChart();
        back.setOnClickListener(listener);

    }

    private void initChart() {
        // 描述，在底部
        mChart.setDescription(" ");
        // 绘制线条宽度，圆形向外辐射的线条
        mChart.setWebLineWidth(1.0f);
        // 内部线条宽度，外面的环状线条
        mChart.setWebLineWidthInner(1.0f);
        // 所有线条WebLine透明度
        mChart.setWebAlpha(100);
        setData();

        XAxis xAxis = mChart.getXAxis();
        // X坐标值字体大小
        xAxis.setEnabled(false);
        xAxis.setTextSize(0f);
        xAxis.setTextColor(Color.parseColor("#FFFFFF"));

        YAxis yAxis = mChart.getYAxis();
        yAxis.setEnabled(false);
        // Y坐标值标签个数
        yAxis.setLabelCount(2, true);
        yAxis.setAxisMaxValue(100);//最大值
        yAxis.setAxisMinValue(0);//最小值
        // Y坐标值字体大小
//        yAxis.setTextColor(Color.parseColor("#ffffff"));
//        yAxis.setTextSize(-1f);
        // Y坐标值是否从0开始
        yAxis.setStartAtZero(false);
        //不显示示例图
        Legend l = mChart.getLegend();
        l.setEnabled(false);
    }
    public void setData() {

        int cnt = 5; // 不同的维度Party A、B、C...总个数

        // Y的值，数据填充
        ArrayList<Entry> yVals = new ArrayList<Entry>();

        yVals.add(new Entry(80, 1));
        yVals.add(new Entry(60, 2));
        yVals.add(new Entry(70, 3));
        yVals.add(new Entry(50, 4));
        yVals.add(new Entry(90, 5));
        // Party A、B、C..
        ArrayList<String> xVals = new ArrayList<String>();

        for (int i = 0; i < cnt; i++) {
            xVals.add("1");
        }
        RadarDataSet set = new RadarDataSet(yVals, " ");
        // Y数据颜色设置 也就是内网的颜色
        set.setColor(Color.parseColor("#FDBDA1"));
        // 是否实心填充区域
        set.setDrawFilled(true);
        // 数据线条宽度
        set.setLineWidth(0.1f);

        ArrayList<RadarDataSet> sets = new ArrayList<RadarDataSet>();
        sets.add(set);

        RadarData data = new RadarData(xVals, sets);
        // 数据字体大小
//        data.setValueTextSize(5f);
        // 是否绘制Y值到图表
        data.setDrawValues(false);
        mChart.setData(data);
        //拖动
        mChart.setRotationEnabled(false);
        mChart.setTouchEnabled(false);
        //内网颜色#FFF0E9
        mChart.setWebColorInner(Color.parseColor("#FFF0E9"));
        mChart.setWebColor(Color.parseColor("#FFF0E9"));
        mChart.invalidate();
    }

    private void initView() {
        back = (ImageView) findViewById(R.id.back);
        mChart = (RadarChart) findViewById(R.id.chart);
        number = (TextView) findViewById(R.id.number);
    }
}
